<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class shop_articleControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			$where=" siteid=".SITEID;
			$url=APPADMIN."?m=shop_article&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("shop_article")->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("shop_article/index.html");
		}
		
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=M("shop_article")->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("shop_article/add.html");
		}
		
		public function onSave(){
			
			$id=get_post("id","i");
			$data["title"]=post("title","h");
			$data["shopid"]=post("shopid","i");
			$data["userid"]=M("login")->userid;
			$data["catid"]=post("catid","i");
			$data["love_num"]=post("love_num","i");
			$data["fav_num"]=post("fav_num","i");
			$data["forward_num"]=post("forward_num","i");
			$data["keywords"]=post("keywords","h");
			$data["description"]=post("description","h");
			$data["dateline"]=time();
			$data["status"]=0;
			$data["comment_num"]=post("comment_num","i");
			$data["model_id"]=post("model_id","i");
			$data["isimg"]=post("isimg","i");
			$data["imgurl"]=post("imgurl","h");
			$data["is_temp"]=post("is_temp","i");
			$data["is_img"]=post("is_img","i");
			$data["thumbsinfo"]=post("thumbsinfo","h");
			$data["last_time"]=post("last_time","i");
			$data["grade"]=post("grade","i");
			$data["is_recommend"]=post("is_recommend","i");
			$data["view_num"]=post("view_num","i");
			$data["user_catid"]=post("user_catid","i");
			$data["shop_cid"]=post("shop_cid","i");
			$data["isnew"]=post("isnew","i");
			$data["ishot"]=post("ishot","i");
			$data["attr_cat_id"]=post("attr_cat_id","i");
			$data["attr_1"]=post("attr_1","i");
			$data["attr_2"]=post("attr_2","i");
			$data["attr_3"]=post("attr_3","i");
			$data["attr_4"]=post("attr_4","i");

			if($id){
				M("shop_article")->update($data,"id='$id'");
			}else{
				M("shop_article")->insert($data);
			}
			$this->gomsg("保存成功");
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			M("shop_article")->update(array("status"=>$status),"id=$id");
			$this->sexit(json_encode(array("error"=>0,"message"=>"状态修改成功")));
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			M("shop_article")->delete("id=".$id);
			$this->sexit(json_encode(array("error"=>0,"message"=>"删除成功")));
		}
		
		
	}

?>